// AppAbout class

package appForm;

import java.awt.Color;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import appPref.Para;

public class AppAbout extends JDialog implements ActionListener {

  private Para para = Para.getPara();

  private static String aboutTitle;
  private static String product;
  private static String version;
  private static String date;
  private static String author1;
  private static String author2;
  private static String author3;
  private static String ok;

  {
    aboutTitle =  para.getT("aboutTitle");
    product    =  para.getT("product");
    version    =  para.getT("version");
    date       =  para.getT("date");
    author1    =  para.getT("author1");
    author2    =  para.getT("author2");
    author3    =  para.getT("author3");
    ok         =  para.getT("ok");
  }

  private JPanel northPanel  = new JPanel();
  private JPanel southPanel  = new JPanel();
  private JPanel centerPanel = new JPanel();
  private JPanel westPanel   = new JPanel();
  private JPanel eastPanel   = new JPanel();
  private JPanel imagePanel  = new JPanel();
  private JPanel textPanel   = new JPanel();

  private static final String IMAGE_PATH = "image/aboutLogo.JPG";

  private ImageIcon imageIcon = para.getImageIcon(IMAGE_PATH);

  private JLabel label1 = new JLabel();
  private JLabel label2 = new JLabel();
  private JLabel label3 = new JLabel();
  private JLabel label4 = new JLabel();
  private JLabel label5 = new JLabel();
  private JLabel label6 = new JLabel();
  private JLabel imageLabel = new JLabel(imageIcon);

  private JButton button = new JButton("OK");

  private BorderLayout borderLayout1 = new BorderLayout();
  private BorderLayout borderLayout2 = new BorderLayout();
  private GridLayout gridLayout = new GridLayout();
  private FlowLayout flowLayout = new FlowLayout();

  public AppAbout(AppFrame parent) {
    super(parent); // different from the default constructor
    try {
      this.init();
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
    this.pack();
  }

  private void init() throws Exception {

    this.setTitle(aboutTitle);
    this.setResizable(false);

    Container cp = this.getContentPane();
    cp.setLayout(borderLayout1);
    cp.add(northPanel, "North");
    cp.add(southPanel, "South");
    cp.add(centerPanel, "Center");
    cp.add(westPanel, "West");
    cp.add(eastPanel, "East");

    centerPanel.setLayout(borderLayout2);
    centerPanel.add(imagePanel, "North");
    centerPanel.add(textPanel, "South");

    imagePanel.setBackground(Color.white);
    imagePanel.add(imageLabel);

    textPanel.setLayout(gridLayout);
    gridLayout.setRows(6);
    gridLayout.setColumns(1);
    label1.setText(product);
    label2.setText(version);
    label3.setText(date);
    label4.setText(author1);
    label5.setText(author2);
    label6.setText(author3);
    textPanel.add(label1);
    textPanel.add(label2);
    textPanel.add(label3);
    textPanel.add(label4);
    textPanel.add(label5);
    textPanel.add(label6);

    southPanel.setLayout(flowLayout);
    southPanel.add(button);
    button.addActionListener(this);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
    this.setVisible(false);
    this.dispose();
    }
  }
}
